package org.aplikator.server.rpc.handler;

import org.aplikator.client.data.PrimaryKey;
import org.aplikator.client.descriptor.PropertyDTO;
import org.aplikator.client.descriptor.ViewDTO;
import org.aplikator.client.rpc.impl.GetRecordCount;
import org.aplikator.client.rpc.impl.GetRecordCountResponse;
import org.aplikator.server.Context;
import org.aplikator.server.persistence.Persister;
import org.aplikator.server.persistence.PersisterFactory;
import org.aplikator.server.rpc.CommandHandler;

public class GetRecordCountHandler implements CommandHandler<GetRecordCount, GetRecordCountResponse> {

    private Persister persister = PersisterFactory.getPersister();

    public GetRecordCountHandler() {

    }

    public GetRecordCountResponse execute(GetRecordCount command, Context ctx) {
        ViewDTO view = command.getView();
        PropertyDTO<Integer> ownerProperty = command.getOwnerProperty();
        PrimaryKey ownerPrimaryKey = command.getOwnerPrimaryKey();
        boolean search = command.getSearch();
        return new GetRecordCountResponse(persister.getRecordCount(view, ownerProperty, ownerPrimaryKey, search, ctx));
    }

}
